import useSys from '../store/useSys'
let perm = {
    mounted: (el, binding, vnode) => {
        bindClick(el, binding, vnode)
    },
    updated: (el, binding, vnode) => {
        el.removeEventListener("click", el.__click_handler__)
        bindClick(el, binding, vnode)
    }
}

function bindClick(el, binding, vnode) {
    let sys = useSys();
    let p = binding.arg;//获取到指令上的参数信息
    sys.hasPermission(p).then(resp => {//resp是查询到后台的菜单信息（权限信息）
        function clickHandler() {
            binding.value(resp, vnode.props.row);
        }
        el.addEventListener("click", clickHandler)
        el.__click_handler__ = clickHandler
    }).catch(error => {
        el.remove();
    })
}

export default perm;